<?php
add_filter('wpjam_basic_setting', function (){
	$site_url = parse_url( site_url() );
	$path = ( !empty( $site_url['path'] ) ) ? $site_url['path'] : '';
	$seo_robots	= '';
	$seo_robots	.= "User-agent: *\n";
	$seo_robots	.= "Disallow: /wp-admin/\n";
	$seo_robots	.= "Disallow: /wp-includes/\n";
	$seo_robots	.= "Disallow: /cgi-bin/\n";
	$seo_robots	.= "Disallow: $path/wp-content/plugins/\n";
	$seo_robots	.= "Disallow: $path/wp-content/themes/\n";
	$seo_robots	.= "Disallow: $path/wp-content/cache/\n";
	$seo_robots	.= "Disallow: $path/author/\n";
	$seo_robots	.= "Disallow: $path/trackback/\n";
	$seo_robots	.= "Disallow: $path/feed/\n";
	$seo_robots	.= "Disallow: $path/comments/\n";
	$seo_robots	.= "Disallow: $path/search/\n";
	
	$seo_fields = array(
		'seo_individual'		=> array('title'=>'独立设置',		'type'=>'checkbox', 'description'=>'文章页面和分类页面独立的 SEO TDK 设置。'),
		'seo_robots'			=> array('title'=>'robots.txt',	'type'=>'textarea',	'value'=>$seo_robots,	'description'=>'如果博客的根目录下已经有 robots.txt 文件，请先删除，否则这里设置的无法生效。'),
	);

	$home_fields = array(
		'seo_home_title'		=> array('title'=>'首页 SEO 标题',	'type'=>'text'),
		'seo_home_description'	=> array('title'=>'首页 SEO 描述',	'type'=>'textarea', 'rows'=>4),
		'seo_home_keywords'		=> array('title'=>'首页 SEO 关键字',	'type'=>'text' ),
	);

	$summary	= '
	<ol>
		<li>可以设置首页的TDK。</li>
		<li>如果没有单独设置，自动获取文章摘要作为文章页面的 Meta Description，可以将文章页面的 Tag 作为 Meta Keywords。</li>
		<li>如果没有单独设置，自动获取分类和 Tag 的描述作为分类和 Tag 页面的 Meta Description。</li>
		<li>如果博客支持并开启固定链接，自动生成 <a href="'.home_url('/robots.txt').'" target="_blank">robots.txt</a> 和 <a href="'.home_url('/sitemap.xml').'" target="_blank">sitemap.xml</a>。</li>
	</ol>';

	$sections = array( 
		'wpjam-seo'	=> array('title'=>'设置',	'fields'=>$seo_fields,	'summary'=>$summary),
		'home-seo'	=> array('title'=>'首页',	'fields'=>$home_fields),
	);

	if(!is_multisite() || (is_multisite() && !is_network_admin())){
		if($post_types = get_post_types(array('public'=> true, 'has_archive'=>true),'objects')){
			foreach ($post_types as $post_type) {
				$post_type_object = get_post_type_object($post_type);
				if(!empty($post_type_object->seo_meta_box) || $post_type == 'post'){
					$post_type_fields = array(
						'seo_'.$post_type->name.'_title'		=> array('title'=>$post_type->label.' SEO 标题',		'type'=>'text'),
						'seo_'.$post_type->name.'_description'	=> array('title'=>$post_type->label.' SEO 描述',		'type'=>'textarea', 'rows'=>4	),
						'seo_'.$post_type->name.'_keywords'		=> array('title'=>$post_type->label.' SEO Keywords','type'=>'text' ),
					);

					$sections[$post_type->name.'-seo']	= array('title'=>$post_type->label, 'fields'=>$post_type_fields);
				}
			}
		}
	}
	
	return compact('sections');
});
